package com.xbai.user.controller;

import com.github.pagehelper.PageInfo;
import com.xbai.entity.Result;
import com.xbai.user.pojo.OauthClientDetails;
import com.xbai.user.service.OauthClientDetailsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc OauthClientDetailsController
 * @author jxbai
 * @date 2021/1/28
 */

@RestController
@RequestMapping("/oauthClientDetails")
@CrossOrigin
@RequiredArgsConstructor
public class OauthClientDetailsController {

    private final OauthClientDetailsService oauthClientDetailsService;

    /***
     * OauthClientDetails分页条件搜索实现
     * @param oauthClientDetails {@link OauthClientDetails}
     * @param page 页码
     * @param size 页大小
     * @return {@link Result<PageInfo>}
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) OauthClientDetails oauthClientDetails, @PathVariable  int page, @PathVariable  int size){
        //调用OauthClientDetailsService实现分页条件查询OauthClientDetails
        PageInfo<OauthClientDetails> pageInfo = oauthClientDetailsService.findPage(oauthClientDetails, page, size);
        return new Result<>(pageInfo);
    }

    /***
     * OauthClientDetails分页搜索实现
     * @param page 页码
     * @param size 页大小
     * @return {@link Result<PageInfo>}
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用OauthClientDetailsService实现分页查询OauthClientDetails
        PageInfo<OauthClientDetails> pageInfo = oauthClientDetailsService.findPage(page, size);
        return new Result<>(pageInfo);
    }

    /***
     * 多条件搜索OauthClientDetails数据
     * @param oauthClientDetails {@link OauthClientDetails}
     * @return {@link Result}
     */
    @PostMapping(value = "/search" )
    public Result<List<OauthClientDetails>> findList(@RequestBody(required = false) OauthClientDetails oauthClientDetails){
        //调用OauthClientDetailsService实现条件查询OauthClientDetails
        List<OauthClientDetails> list = oauthClientDetailsService.findList(oauthClientDetails);
        return new Result<>(list);
    }

    /***
     * 根据ID删除OauthClientDetails数据
     * @param id 主键id
     * @return {@link Result}
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        //调用OauthClientDetailsService实现根据主键删除
        oauthClientDetailsService.delete(id);
        return new Result();
    }

    /***
     * 修改OauthClientDetails数据
     * @param oauthClientDetails {@link OauthClientDetails}
     * @param id 主键id
     * @return {@link Result}
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody OauthClientDetails oauthClientDetails, @PathVariable String id){
        //设置主键值
        oauthClientDetails.setClientId(id);
        //调用OauthClientDetailsService实现修改OauthClientDetails
        oauthClientDetailsService.update(oauthClientDetails);
        return new Result();
    }

    /***
     * 新增OauthClientDetails数据
     * @param oauthClientDetails {@link OauthClientDetails}
     * @return {@link Result}
     */
    @PostMapping
    public Result add(@RequestBody OauthClientDetails oauthClientDetails){
        //调用OauthClientDetailsService实现添加OauthClientDetails
        oauthClientDetailsService.add(oauthClientDetails);
        return new Result();
    }

    /***
     * 根据ID查询OauthClientDetails数据
     * @param id 主键id
     * @return {@link Result}
     */
    @GetMapping("/{id}")
    public Result<OauthClientDetails> findById(@PathVariable String id){
        //调用OauthClientDetailsService实现根据主键查询OauthClientDetails
        OauthClientDetails oauthClientDetails = oauthClientDetailsService.findById(id);
        return new Result<>(oauthClientDetails);
    }

    /***
     * 查询OauthClientDetails全部数据
     * @return {@link Result}
     */
    @GetMapping
    public Result<List<OauthClientDetails>> findAll(){
        //调用OauthClientDetailsService实现查询所有OauthClientDetails
        List<OauthClientDetails> list = oauthClientDetailsService.findAll();
        return new Result<>(list) ;
    }
}
